<template>
  <div class="login-content">
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="username"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="password"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px;">
        <van-button round block type="info" native-type="submit">
          提交
        </van-button>
      </div>
    </van-form>
   <van-row type="flex" justify="space-between">
      <van-col span="6" class="text-align" @click="$router.push('/register')">立即注册</van-col>
      <van-col span="6" class="text-align">忘记密码</van-col>
    </van-row>
    <div class="copyright">
      &copy; 简影 客服电话：
      <span>8008208820</span>
    </div>
  </div>
</template>

<script>
import { mapState, mapActions } from 'vuex'

export default {
  name: 'Login',
  data () {
    return {
      username: '',
      password: ''
    }
  },
  computed: {
    ...mapState('user', ['token'])
  },
  methods: {
    ...mapActions('user', ['loginAsync']),
    onSubmit (e) {
      console.log(e)
      const result = this.loginAsync(e)
      console.log(this.loginAsync(e))
      console.log('登录：', result)
      this.loginAsync(e).then(res => {
        console.log(res)
        if (res.status === 200) {
          const { to = '/mine' } = this.$route.params
          this.$router.push(to)
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.text-align {
  text-align: center;
  color: #FE8C00;
  font-size: 14px;
}
.copyright {
  text-align: center;
  margin-top: 15px;
  font-size: 16px;
  span {
    color: skyblue;
  }
}
</style>
